<template>
  <view class="wrap">
    <view class="card">
      <view class="title">登录</view>

      <input v-model="form.username" class="input" placeholder="请输入用户名" />
      <input v-model="form.password" class="input" password placeholder="请输入密码" />

      <button class="btn" :disabled="!canSubmit" @click="toLogin">登录</button>

      <view class="link" @click="toRegPage">没有账号？<text class="blue">去注册</text></view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      form: { username: '', password: '' }
    }
  },
  computed: {
    canSubmit() {
      return this.form.username && this.form.password
    }
  },
methods: {
toLogin() {
  const { username, password } = this.form
  if (username.length < 3) return uni.showToast({ title: '用户名至少3位', icon: 'none' })
  if (password.length < 6) return uni.showToast({ title: '密码至少6位', icon: 'none' })

  if (!uni.getStorageSync('hasReg')) {
    uni.showToast({ title: '请先完成注册', icon: 'none' })
    return
  }

  /* ✅ 一次性：立即删除钥匙 + 提示 */
  uni.removeStorageSync('hasReg')
  uni.showToast({ title: '本次登录成功，激活码已用完请重新注册', icon: 'none' })

  // uni.showToast({ title: '登录成功', icon: 'success' })
  setTimeout(() => uni.switchTab({ url: '/pages/module/module' }), 2000)
},
  toRegPage() {
    uni.navigateTo({ url: '/pages/register/register' })
  }
}
}
</script>

<style>
.wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
}
.card {
  width: 600rpx;
  padding: 60rpx 50rpx;
  background: #fff;
  border-radius: 16rpx;
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
}
.title {
  font-size: 40rpx;
  font-weight: 600;
  text-align: center;
  margin-bottom: 50rpx;
}
.input {
  height: 88rpx;
  padding: 0 24rpx;
  margin-bottom: 30rpx;
  border: 2rpx solid #e5e5e5;
  border-radius: 8rpx;
  font-size: 30rpx;
}
.btn {
  height: 88rpx;
  line-height: 88rpx;
  background: #2979ff;
  color: #fff;
  border-radius: 8rpx;
  font-size: 32rpx;
}
.btn[disabled] {
  background: #a8c5ff;
}
.link {
  margin-top: 30rpx;
  text-align: center;
  font-size: 28rpx;
  color: #666;
}
.blue {
  color: #2979ff;
}
</style>